<?php

namespace app\common\model\search;

trait PropagandaEducationSearch
{
    public function searchNameAttr($query, $value, $data)
    {
        return $query->where('name', 'like', $value);
    }

    public function searchClassifyAttr($query, $value, $data)
    {
        $list = $query->select()->toArray();

        $ids = [];
        foreach($list as $k => $v)
        {
            foreach($v['classify'] as $k2 => $v2)
            {
                if ($v2['value'] == $value)
                {
                    $ids[] = $v['id'];
                }
            }
        }
        return $query->whereIn('id', $ids); 
    }

}